home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Frameworks / DropShell++ / Touch ƒ / touchshell.cp < prev    next >
Encoding:
Text File  |  1994-11-30  |  2.5 KB  |  104 lines  |  [TEXT/KAHL]

  1.  
  2. void main()
  3. {
  4.     touchsettings defaultSettings =
  5.     {
  6.         touchshell::kSecondButton,
  7.         touchshell::kModDate
  8.     };
  9.     StringHandle prefsFileHandle = GetString( 128);
  10.     touchshell it( *(Str255 *)*prefsFileHandle, defaultSettings);
  11.     it.run();
  12. }
  13.  
  14. touchshell::touchshell( Str255 prefsFileName, touchsettings &defaultsettings)
  15.         : dropshell()
  16.         , touchprefs( prefsFileName, defaultsettings)
  17. {    
  18.     Handle times = Get1Resource( 'tims', 128);
  19.     
  20.     MoveHHi( times);
  21.     HLock( times);
  22.     
  23.     theGrains = (long *)*times;
  24.     
  25.     GetDateTime( &starting_time);
  26.     ChangeGrain( whichGrain);
  27.     ChangeDate( whichDate);
  28. }
  29.  
  30. void touchshell::OpenDoc( Boolean opening)
  31. {
  32.     if( opening)
  33.     {
  34.         if( whichDate != kModDate)
  35.         {
  36.             theCInfoPBRec.hFileInfo.ioFlCrDat = time_to_set;
  37.         }
  38.         if( whichDate != kCreatDate)
  39.         {
  40.             theCInfoPBRec.hFileInfo.ioFlMdDat = time_to_set;
  41.         }
  42.         theCInfoPBRec.hFileInfo.ioFDirIndex = 0;
  43.         const OSErr result = PBSetCatInfoSync( &theCInfoPBRec);
  44.         if( result != noErr)
  45.         {
  46.             SysBeep( 9);
  47.         }
  48.     }
  49. }
  50.  
  51. void touchshell::HandleDialogEvent( short itemHit, DialogPtr theDialog)
  52. {
  53.     switch( itemHit)
  54.     {
  55.         case kSecondButton:
  56.         case kMinuteButton:
  57.         case kHourButton:
  58.         case kHalfDayButton:
  59.         case kDayButton:
  60.         case kGroundZeroButton:
  61.             ChangeGrain( itemHit);
  62.             break;
  63.             
  64.         case kCreatDate:
  65.         case kModDate:
  66.         case kBothDates:
  67.             ChangeDate( itemHit);
  68.             break;
  69.     }
  70. }
  71.  
  72. void touchshell::ChangeGrain( int newGrain)
  73. {
  74.     short    iType;
  75.     Handle    iHandle;
  76.     Rect    iRect;
  77.  
  78.     for( int i = kSecondButton; i <= kGroundZeroButton; i++)
  79.     {
  80.         GetDItem( gMainDialog, i, &iType, &iHandle, &iRect);
  81.         SetCtlValue( (ControlHandle)iHandle, (i == newGrain));
  82.     }
  83.     whichGrain = newGrain;
  84.     const long granularity = theGrains[ whichGrain - 1];
  85.     
  86.     time_to_set = granularity *
  87.         ((starting_time + granularity - 1) / granularity);
  88. }
  89.  
  90. void touchshell::ChangeDate( int newDate)
  91. {
  92.     short    iType;
  93.     Handle    iHandle;
  94.     Rect    iRect;
  95.  
  96.     for( int i = kCreatDate; i <= kBothDates; i++)
  97.     {
  98.         GetDItem( gMainDialog, i, &iType, &iHandle, &iRect);
  99.         SetCtlValue( (ControlHandle)iHandle, (i == newDate));
  100.     }
  101.     whichDate = newDate;
  102. }
  103.